package site.qianli.discover.service.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Aspect
public class ServiceAspect {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Before("execution(* site.qianli.discover.service..*(..))")
	public void beforeAdvice(JoinPoint joinPoint) throws Throwable {
		logger.info("@Before:{}.{}", joinPoint.getSignature().getDeclaringTypeName(),
				joinPoint.getSignature().getName());
	}

	@After("execution(* site.qianli.discover.service..*(..))")
	public void afterAdvice() {
		logger.info("@After");
	}

	@Around("execution(* site.qianli.discover.service..*(..))")
	public Object process(ProceedingJoinPoint point) throws Throwable {
		logger.info("@Around:执行目标方法之前...");
		Object[] args = point.getArgs();
		logger.info("@Around参数:{}", args);
		Object returnValue = point.proceed(args);
		logger.info("@Around：执行目标方法之后...");
		logger.info("@Around：被织入的目标对象为：" + point.getTarget());
		return returnValue;
	}

	@AfterThrowing(throwing = "ex", pointcut = "execution(* site.qianli.discover.service..*(..))")
	public void afterThrowing(Throwable ex) {
		logger.info("@AfterThrowing:{}", ex.getMessage());
	}

	@AfterReturning(returning = "returnValue", pointcut = "execution(* site.qianli.discover.service..*(..))")
	public void afterReturning(Object returnValue) {
		logger.info("@AfterReturning:{}", returnValue.toString());
	}

}
